package com.cnaaa.pay.timer;

import com.alipay.api.AlipayApiException;
import com.cnaaa.pay.service.TradeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 2018/10/29 Create by 郭文梁
 * CloseTimeoutTradeTimer
 * 顶你是个hi执行，负责关闭超时订单
 *
 * @author 郭文梁
 * @date 2018/10/29
 */
@Component
@Slf4j
public class CloseTimeoutTradeTimer {
    private final TradeService tradeService;

    @Autowired
    public CloseTimeoutTradeTimer(TradeService tradeService) {
        this.tradeService = tradeService;
    }

    @Scheduled(fixedRate = 300000)
    public void closeTimeoutTrades() throws AlipayApiException {
        int count = tradeService.closeTimeoutAlipayTrade();
        log.info("Close {} timeout trade", count);
    }
}
